package com.xyh.controller;

import com.xyh.po.User;
import com.xyh.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:kyle
 * @Date:2020/12/16 - 13:14
 * @Project:spring_demo1
 * @Package:com.xyh.controller
 * @Version:1.0
 */
@org.springframework.stereotype.Controller
@RequestMapping("/user")
public class HelloController3 implements Controller {

    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/helloController")
    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        Map<String, Object> map = new HashMap<>();
        map.put("username","金庸");
        List<User> users = userService.listByMap(map);

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("controller",users);
        modelAndView.setViewName("hello");
        return modelAndView;
    }
}
